import static org.junit.Assert.*;

import java.util.BitSet;
import java.util.Random;

import org.junit.Test;


public class testBoolArrayBitSet 
{
	
	private class BoolArrayBitSet
	{
		private BitSet bitSet;
		private int yOffset;
		
		public BoolArrayBitSet( int xWidth, int yHeight )
		{
			bitSet = new BitSet( xWidth*yHeight );
			yOffset = yHeight;
		}
		
		private int convertXYIntoOffset( int x, int y )
		{
			return x+(y*yOffset);
		}
		
		public void set( int x, int y, boolean value )
		{
			bitSet.set( convertXYIntoOffset(x,y) , value);
		}
		
		public boolean get( int x, int y )
		{
			return bitSet.get( convertXYIntoOffset(x,y) );
		}
	}
	
	@Test
	public void test() 
	{
		
		Random random = new Random();
		
//		for ( int loop = 0; loop < 10; loop++)
//		{
			int width = random.nextInt(10000);
			int height = random.nextInt(10000);
			
			boolean[][] boolArray = new boolean[width][height];
			BoolArrayBitSet boolBitSet = new BoolArrayBitSet( width, height );

			for ( int w = 0; w < width; w++ )
			{
				for ( int h = 0; h < height; h++ )
				{
					boolean randomValue = random.nextBoolean();
					boolArray[w][h] = randomValue;
					boolBitSet.set(w, h, randomValue );
				}
			}
			
			BoolArrayBitSet testSet = new BoolArrayBitSet(10,10);
			
			assertTrue( testSet.convertXYIntoOffset(0, 0) == 0 );
			assertTrue( testSet.convertXYIntoOffset(0, 1) == 10 );
			
			assertTrue( testSet.convertXYIntoOffset(9, 9) == 99 );
			assertTrue( testSet.convertXYIntoOffset(1, 0) == 1 );
			
			assertTrue( testSet.convertXYIntoOffset(5, 4) == 45 );

			for ( int w = 0; w < boolArray.length; w++ )
			{
				for ( int h = 0; h < boolArray[0].length; h++ )
				{
//					System.out.println( boolArray[w][h]+" == "+boolBitSet.get(w, h));
					if ( boolArray[w][h] != boolBitSet.get(w, h) )
					{
						System.out.println( boolArray[w][h]+" == "+boolBitSet.get(w, h));
						System.out.println( "w = "+w+", h = "+h);
					}
					
					assertTrue( boolArray[w][h] == boolBitSet.get(w, h) );
				}
			}
//		}
			
	}

}
